<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Models\CompanyInformation;

class CompanyInformationController extends Controller
{
  use ModelForm;
  public function index()
  {
      return Admin::content(function (Content $content) {
          $content->header('公司企业信息');
          $content->description('管理');
          $content->body($this->grid());
      });
  }

  public function edit($id)
  {
      return Admin::content(function (Content $content) use ($id) {
          $content->header('企业信息');
          $content->description('编辑');

          $content->body($this->form()->edit($id));
      });
  }

  public function create()
  {
      return Admin::content(function (Content $content) {
          $content->header('企业信息');
          $content->description('创建');

          $content->body($this->form());
      });
  }

  protected function grid()
  {
      return Admin::grid(CompanyInformation::class, function (Grid $grid) {
          // $grid->position_tags('轮播图序号');
          $grid->id('序号');
          $grid->name('企业名称');
          $grid->enterprise_concept('企业理念');
          $grid->img('企业头像')->image();
          $grid->telephone('联系电话');
          $grid->contact_address('联系地址');
          $grid->disableFilter();
          $grid->disableExport();
          // $grid->disableCreateButton();
          // $grid->disablePagination();
          $grid->disableFilter();
          $grid->paginate(10);
          $grid->perPages([10,20,30]);
          $grid->disableRowSelector();
          $grid->disableCreateButton();
          // $grid->disableActions();
          $grid->actions(function ($actions) {
              // $actions->disableDelete();
              $actions->disableDelete();
          });
      });
  }

  protected function form()
  {
      return Admin::form(CompanyInformation::class, function (Form $form) {
          $form->text('name', '企业名称');
          // $form->textarea($column['enterprise_concept', ''])->rows(10);
          $form->textarea("enterprise_concept","企业理念")->rows(3)->rules('required|min:2',[
         'required' => '企业理念不能为空!',
         'min' => '字符必须大于2个!'
]);
          $form->text('telephone', '联系电话')->rules('required',[
         'required' => '电话不能为空!'
]);;
          $form->textarea("contact_address","联系地址")->rows(3)->rules('required|min:2',[
         'required' => '联系地址不能为空!',
         'min' => '字符必须大于2个!'
]);
          $form->image('img', '企业头像')->rules('required',[
         'required' => '企业头像不能为空!'
]);;
      });
  }
  }
